package com.jsgt.greekfire.ui.dialog

import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.jsgt.greekfire.R
import com.jsgt.greekfire.base.BaseBottomDialogFragment
import org.jetbrains.anko.find

class ManageAddWalletDialog(): BaseBottomDialogFragment() {
    lateinit var createListener: () -> Unit
    lateinit var mnemonicListener: () -> Unit
    lateinit var keyListener: () -> Unit

    constructor(title:String):this(){
        arguments = Bundle()
        arguments?.putString("title", title)
    }

    fun createListener(createListener: () -> Unit): ManageAddWalletDialog {
        this.createListener = createListener
        return this
    }

    fun mnemonicListener(mnemonicListener: () -> Unit): ManageAddWalletDialog {
        this.mnemonicListener = mnemonicListener
        return this
    }

    fun keyListener(keyListener: () -> Unit): ManageAddWalletDialog {
        this.keyListener = keyListener
        return this
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_manage_add_wallet
    }

    override fun getDialogStyle(): Int {
        return R.style.DialogTheme
    }

    override fun canCancel(): Boolean {
        return true
    }

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)
        dialog.find<TextView>(R.id.txvTitle).text = arguments?.getString("title")
        dialog.find<ImageView>(R.id.imvClose).setOnClickListener {
            dismiss()
        }
        dialog.find<View>(R.id.vCreate).setOnClickListener {
            createListener.invoke()
            dismiss()
        }
        dialog.find<View>(R.id.vMnemonic).setOnClickListener {
            mnemonicListener.invoke()
            dismiss()
        }
        dialog.find<View>(R.id.vKey).setOnClickListener {
            keyListener.invoke()
            dismiss()
        }
        return dialog
    }
}